const mongoose = require('mongoose')
const Schema = mongoose.Schema
const menuSchema = new Schema({
  menuType: { // 菜单类型 0：菜单 1：按钮
    type: Number,
    default: 0
  },
  title: String, // 菜单名称
  iconName: String, // 菜单图标
  path: String, // 访问路径
  parentId: // 上级菜单id
  {
    type: mongoose.Schema.Types.ObjectId,
    ref: 'menus'
  }
},
  {
    toJSON: { virtuals: true },
    toObject: { virtuals: true }
  })

// 子菜单列表
menuSchema.virtual('children', {
  localField: '_id',
  ref: 'menus',
  foreignField: 'parentId',
  justOne: false
})


module.exports = mongoose.model('menus', menuSchema, 'menus')